#!/bin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

cat >console-login.xml <<EOF
<?xml version="1.0"?>
<!--
	Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
	Use is subject to license terms.

	NOTE:  This service manifest is not editable; its contents will
	be overwritten by package or patch operations, including
	operating system upgrade.  Make customizations in a different
	file.
-->

<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">

<service_bundle type='manifest' name='SUNWcsr:console'>

<service
	name='system/console-login'
	type='service'
	version='1'>

	<dependency
		name='fs'
		grouping='require_all'
		restart_on='none'
		type='service'>
		<service_fmri value='svc:/system/filesystem/minimal' />
	</dependency>

	<dependency
		name='identity'
		grouping='require_all'
		restart_on='none'
		type='service'>
		<service_fmri value='svc:/system/identity:node' />
	</dependency>

	<dependency
		name='utmpx'
		grouping='require_all'
		restart_on='none'
		type='service'>
		<service_fmri value='svc:/system/utmp:default' />
	</dependency>

	<!-- Note that console-login should be dependent on any services
	     that may need to use the console. This requirement can be met
	     by establishing a dependency on milestone/sysconfig which,
	     among other things, collects such dependencies.
	-->
	<dependency
		name='sysconfig'
		grouping='require_all'
		restart_on='none'
		type='service'>
		<service_fmri value='svc:/milestone/sysconfig' />
	</dependency>

	<exec_method
		type='method'
		name='start'
		exec='/lib/svc/method/console-login %i'
		timeout_seconds='0'>
                <method_context>
                        <method_credential user='root' group='root' />
                </method_context>
        </exec_method>

	<exec_method
		type='method'
		name='stop'
		exec=':kill -9'
		timeout_seconds='3'>
                <method_context>
                        <method_credential user='root' group='root' />
                </method_context>
        </exec_method>


	<property_group name='startd' type='framework'>
		<propval name='duration' type='astring' value='child' />
		<propval name='ignore_error' type='astring'
			value='core,signal' />
		<propval name='utmpx_prefix' type='astring' value='co' />
	</property_group>

	<property_group name='general' type='framework'>
		<propval name='action_authorization' type='astring'
			value='solaris.smf.manage.vt' />
		<propval name='value_authorization' type='astring'
			value='solaris.smf.manage.vt' />
	</property_group>

	<!-- these are passed to ttymon in the method script.
	     note that value_authorization is not passed to ttymon
	     and it's for smf_security(7).
	-->
	<property_group name='ttymon' type='application'>
		<propval name='value_authorization' type='astring'
			value='solaris.smf.value.vt' />
		<propval name='device' type='astring' value='/dev/console' />
		<propval name='label' type='astring' value='console' />
		<propval name='timeout' type='count' value='0' />
		<propval name='nohangup' type='boolean' value='true' />
		<propval name='modules' type='astring'
		    value='ldterm,ttcompat' />
		<propval name='prompt' type='astring'
		   value='\`uname -n\` console login:' />
		<propval name='terminal_type' type='astring'
		     value='' />
	</property_group>


<instance name='default' enabled='true'>
</instance>

EOF

# consoles on serials ports
for num in a b c d; do
	cat >>console-login.xml <<EOF

<instance name='tty$num' enabled='true'>

	<dependency
		name='system-console'
		grouping='require_all'
		restart_on='none'
		type='service'>
		<service_fmri value='svc:/system/console-login:default' />
	</dependency>

	<!-- these are passed to ttymon in the method script -->
	<property_group name='ttymon' type='application'>
		<propval name='value_authorization' type='astring'
			value='solaris.smf.value.vt' />
		<propval name='device' type='astring' value='/dev/term/$num' />
		<propval name='label' type='astring' value='115200' />
		<propval name='timeout' type='count' value='0' />
		<propval name='nohangup' type='boolean' value='true' />
		<propval name='modules' type='astring'
			value='ldterm,ttcompat' />
		<propval name='prompt' type='astring'
			value='\`uname -n\` tty$num login:' />
		<propval name='terminal_type' type='astring'
			value='xterm' />
	</property_group>
</instance>

EOF
done

# Note that this script file is normally parsed during build by sh(1).
# When the parser encounters an EOF token (like the one above), it
# will fork off and pipe all the text after the EOF above to the shell
# for execution.
#
# one system console (/dev/console) plus five virtual consoles
# (/dev/vt/#, # is from 2 to 6).

for num in 2 3 4 5 6; do
	cat >>console-login.xml <<EOF

<instance name='vt$num' enabled='false'>

	<dependency
		name='system-console'
		grouping='require_all'
		restart_on='none'
		type='service'>
		<service_fmri value='svc:/system/console-login:default' />
	</dependency>

	<dependency
		name='vtdaemon'
		grouping='require_all'
		restart_on='none'
		type='service'>
		<service_fmri value='svc:/system/vtdaemon:default' />
	</dependency>

        <!-- these are passed to ttymon in the method script -->
        <property_group name='ttymon' type='application'>
		<propval name='value_authorization' type='astring'
			value='solaris.smf.value.vt' />
		<propval name='device' type='astring' value='/dev/vt/$num' />
		<propval name='label' type='astring' value='console' />
		<propval name='timeout' type='count' value='0' />
		<propval name='nohangup' type='boolean' value='true' />
		<propval name='modules' type='astring'
			value='ldterm,ttcompat' />
		<propval name='prompt' type='astring'
			value='\`uname -n\` vt$num login:' />
		<propval name='terminal_type' type='astring'
			value='' />
	</property_group>

</instance>

EOF
done

cat >>console-login.xml <<EOF

	<stability value='Evolving' />

	<template>
		<common_name>
			<loctext xml:lang='C'>
Console login
			</loctext>
		</common_name>
		<documentation>
			<manpage title='ttymon' section='8'
				manpath='/usr/share/man' />
		</documentation>

		<pg_pattern name='ttymon' type='application' target='this'
		    required='false'>
			<prop_pattern name='device' type='astring'
			    required='false'>
				<description>
					<loctext xml:lang='C'>
The terminal device to be used for the console login prompt.
					</loctext>
				</description>
				<visibility value='readwrite'/>
				<cardinality min='1' max='1'/>
				<values>
					<value name='/dev/console'>
						<description>
							<loctext xml:lang='C'>
The default console device
							</loctext>
						</description>
					</value>
					<value name='/dev/wscons'>
						<description>
							<loctext xml:lang='C'>
The physical workstation console (i.e. keyboard and monitor)
							</loctext>
						</description>
					</value>
					<value name='/dev/term/a'>
						<description>
							<loctext xml:lang='C'>
Serial device A
							</loctext>
						</description>
					</value>
					<value name='/dev/term/b'>
						<description>
							<loctext xml:lang='C'>
Serial device B
							</loctext>
						</description>
					</value>
				</values>
				<choices>
					<include_values type='values'/>
				</choices>
			</prop_pattern>
			<prop_pattern name='label' type='astring'
			    required='false'>
				<common_name>
					<loctext xml:lang='C'>
/etc/ttydefs entry
					</loctext>
				</common_name>
				<description>
					<loctext xml:lang='C'>
The appropriate entry from /etc/ttydefs
					</loctext>
				</description>
				<visibility value='readwrite'/>
				<cardinality min='1' max='1'/>
			</prop_pattern>
			<prop_pattern name='timeout' type='count'
			    required='false'>
				<description>
					<loctext xml:lang='C'>
If no user input is given within the number of seconds defined by this property after the prompt is printed, ttymon should exit.
					</loctext>
				</description>
				<units>
					<loctext xml:lang='C'>
seconds
					</loctext>
				</units>
				<visibility value='readwrite'/>
				<cardinality min='1' max='1'/>
			</prop_pattern>
			<prop_pattern name='nohangup' type='boolean'
			    required='false'>
				<description>
					<loctext xml:lang='C'>
Do not force a hangup on the line by setting the speed to zero before setting the speed to the default or specified speed.
					</loctext>
				</description>
				<visibility value='readwrite'/>
				<cardinality min='1' max='1'/>
			</prop_pattern>
			<prop_pattern name='modules' type='astring'
			    required='false'>
				<common_name>
					<loctext xml:lang='C'>
STREAMS modules
					</loctext>
				</common_name>
				<description>
					<loctext xml:lang='C'>
STREAMS modules to be pushed on the terminal
					</loctext>
				</description>
				<visibility value='readwrite'/>
				<internal_separators>,</internal_separators>
			</prop_pattern>
			<prop_pattern name='prompt' type='astring'
			    required='false'>
				<description>
					<loctext xml:lang='C'>
Prompt to be printed on console
					</loctext>
				</description>
				<visibility value='readwrite'/>
				<cardinality min='1' max='1'/>
			</prop_pattern>
			<prop_pattern name='terminal_type' type='astring'
			    required='false'>
				<description>
					<loctext xml:lang='C'>
Sets the initial value of the TERM environment variable
					</loctext>
				</description>
				<visibility value='readwrite'/>
				<cardinality min='1' max='1'/>
			</prop_pattern>
		</pg_pattern>

	</template>
</service>

</service_bundle>
EOF
